import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

// 后台路由对照表
export const components = {
    '@/views/dashboard/index': () =>
        import('@/views/dashboard/index'), // 首页
    // '@/views/home/index': () => import('@/views/dashboard/index'), // 首页2
    '@/views/home/index': () =>
        import('@/views/home/index'), // 首页2
    '@/views/admin/index': () =>
        import('@/views/admin/index'), // 管理员列表
    '@/views/permission/page': () =>
        import('@/views/permission/page'), // 资源管理
    '@/views/permission/page-wuye': () =>
        import('@/views/permission/page-wuye'), // 资源管理（物业）
    '@/views/permission/role': () =>
        import('@/views/permission/role'), // 权限组管理
    '@/views/permission/payConfig': () =>
        import('@/views/permission/pay-config'), // 支付配置
    '@/views/system-layout/index': () =>
        import('@/views/system-layout/index'), // 系统配置
    '@/views/file/index': () =>
        import('@/views/file/index'), // 文件管理
    '@/views/dictionary/index': () =>
        import('@/views/dictionary/index'), // 数据字典
    '@/views/log-manage/index': () =>
        import('@/views/log-manage/index'), // 日志管理
    '@/views/system-layout/list': () =>
        import('@/views/system-layout/list'), // 系统全局配置
    '@/views/wx/user-list': () =>
        import('@/views/wx/user-list'), // 微信用户列表
    '@/views/wx/config-list': () =>
        import('@/views/wx/config-list'), // 微信配置列表

    // ***********************
    // 物业管理
    '@/pages/wuye/wuye-list': () =>
        import('@/pages/wuye/wuye-list'), // 物业公司
    '@/pages/wuye/house': () =>
        import('@/pages/wuye/house'), // 小区管理
    '@/pages/wuye/user': () =>
        import('@/pages/wuye/user'), // 用户管理
    '@/pages/wuye/zuke-yezhu-list': () =>
        import('@/pages/wuye/zuke-yezhu-list'), // 租客/业主列表
    '@/pages/wuye/fy-list': () =>
        import('@/pages/wuye/fy-list'), // 房源管理
    // 报修管理
    '@/pages/repairs/list': () =>
        import('@/pages/repairs/list'), // 投诉表彰
    // 物业缴费
    '@/pages/pay-the-fees/list': () =>
        import('@/pages/pay-the-fees/list'), // 物业缴费
    // 应用中心
    '@/pages/application-center/list': () =>
        import('@/pages/application-center/list'), // 应用中心
    // 小程序
    '@/pages/xcx/list': () =>
        import('@/pages/xcx/list'), // 小程序列表
    '@/pages/xcx/dmk': () =>
        import('@/pages/xcx/dmk'), // 小程序代码库
    '@/pages/xcx/ext': () =>
        import('@/pages/xcx/ext'), // 小程序ext
    //企业微信
    '@/pages/qywx/index': () =>
        import('@/pages/qywx/index'), // 企业微信
    //门禁管理
    '@/pages/entrance-guard/list': () =>
        import('@/pages/entrance-guard/list'), // 门禁广告列表
    '@/pages/entrance-guard/device': () =>
        import('@/pages/entrance-guard/device'), // 门禁设备
    '@/pages/entrance-guard/webrtc-list': () =>
        import('@/pages/entrance-guard/webrtc-list'), // webrtc设备
    '@/pages/entrance-guard/im-list': () =>
        import('@/pages/entrance-guard/im-list'), // im列表
    '@/pages/entrance-guard/agent-list': () =>
        import('@/pages/entrance-guard/agent-list'), // 代理商管理
    '@/pages/entrance-guard/device-type': () =>
        import('@/pages/entrance-guard/device-type'), // 设备品牌
    '@/pages/entrance-guard/device-sub-type': () =>
        import('@/pages/entrance-guard/device-sub-type'), // 设备类型

    // 商城管理
    '@/pages/mall/shop-list': () =>
        import('@/pages/mall/shop-list'), // 商家列表
    '@/pages/mall/shop-admin': () =>
        import('@/pages/mall/shop-admin'), // 门店管理员列表
    '@/pages/mall/shop-permission': () =>
        import('@/pages/mall/shop-permission'), // 资源管理
    '@/pages/mall/order/list': () =>
        import('@/pages/mall/order/list'), // 订单列表
    '@/pages/mall/order/chargeback-list': () =>
        import('@/pages/mall/order/chargeback-list'), // 退单列表

    // 供应商管理
    '@/pages/gys/list': () =>
        import('@/pages/gys/list'), // 供应商列表
    '@/pages/gys/permission': () =>
        import('@/pages/gys/permission'), // 供应商资源管理
    '@/pages/gys/user': () =>
        import('@/pages/gys/user'), // 供应商管理员

    // 充电桩
    '@/views/site-pile-point/site-admin': () =>
        import('@/views/site-pile-point/site-admin'), // 站点管理
    '@/views/site-pile-point/equipment-admin': () =>
        import('@/views/site-pile-point/equipment-admin'), // 设备管理
    '@/views/site-pile-point/pile-point-admin': () =>
        import('@/views/site-pile-point/pile-point-admin'), // 桩点管理
    '@/views/site-pile-point/site-audit': () =>
        import('@/views/site-pile-point/site-audit'), // 站点审核
    '@/views/order/list': () =>
        import('@/views/order/list'), // 订单管理 - 订单列表
    '@/views/order/refund-list': () =>
        import('@/views/order/refund-list'), // 订单管理 - 退单列表
    '@/views/agent-admin/index': () =>
        import('@/views/agent-admin/index'), // 代理商管理
    '@/views/level-management/index': () =>
        import('@/views/level-management/index'), // 代理商级别管理
    '@/views/beneficiary/index': () =>
        import('@/views/beneficiary/index'), // 受益方管理
    '@/views/sub-account/index': () =>
        import('@/views/sub-account/index'), // 分账模板
    '@/views/charge-template/index': () =>
        import('@/views/charge-template/index'), // 收费模板

    '@/views/permission/news-list': () =>
        import('@/views/permission/news-list'), // 官网新闻管理

    // 自助洗车
    '@/views/washer/devices/index': () =>
        import('@/views/washer/devices/index'), // 设备管理
    '@/views/washer/order/list': () =>
        import('@/views/washer/order/list'), // 订单列表

    // 业委管理
    '@/pages/yewei/user': () =>
        import('@/pages/yewei/user'), // 用户管理

    // 居委管理
    '@/pages/juwei/user': () =>
        import('@/pages/juwei/user'), // 用户管理

}

export const constantRoutes = [
    // {
    //   path: '/home/index',
    //   hidden: true,
    //   component: () => import('@/views/dashboard/index'),
    // },

    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        children: [{
            path: 'dashboard',
            component: () =>
                import('@/views/dashboard/index'),
            name: 'Dashboard',
            meta: {
                title: '首页',
                icon: 'dashboard',
                affix: true
            }
        }]
    },

    // {
    //   path: '/home',
    //   component: Layout,
    //   hidden: true,
    //   children: [{
    //     path: '/index',
    //     component: () => import('@/views/dashboard/index')
    //   }]
    // },
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [{
            path: '/redirect/:path(.*)',
            component: () =>
                import('@/views/redirect/index')
        }]
    },
    {
        path: '/loginSb',
        component: () =>
            import('@/views/login/indexSb'),
        hidden: true
    },
    {
        path: '/login',
        component: () =>
            import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/cardInfo',
        component: () =>
            import('@/views/login/sky'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () =>
            import('@/views/login/auth-redirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () =>
            import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () =>
            import('@/views/error-page/401'),
        hidden: true
    },
    {
        path: '/test',
        component: Layout,
        hidden: true,
        children: [{
            path: 'test',
            component: () =>
                import('@/views/home/index'),
            name: 'test',
            meta: {
                title: '调试页面'
            }
        }]
    },
    {
        path: '/profile',
        component: Layout,
        redirect: '/profile/index',
        hidden: true,
        children: [{
            path: 'index',
            component: () =>
                import('@/views/profile/index'),
            name: 'Profile',
            meta: {
                title: 'profile',
                icon: 'user',
                noCache: true
            }
        },
        {
            path: 'upd-password',
            component: () =>
                import('@/views/profile/upd-password'),
            name: 'UpdPassword',
            meta: {
                title: '修改密码',
                icon: 'el-icon-edit',
                noCache: true
            }
        }
        ]
    },
    {
        path: '/admin',
        component: Layout,
        name: 'admin',
        hidden: true,
        children: [{
            path: '/',
            component: () =>
                import('@/views/admin/index'),
            name: 'Index',
            meta: {
                title: '管理员列表',
                noCache: true
            }
        },
        {
            path: 'adduser',
            component: () =>
                import('@/views/admin/adduser'),
            name: 'AddUser',
            meta: {
                title: '管理员添加',
                noCache: true
            }
        },
        {
            path: 'upduser',
            component: () =>
                import('@/views/admin/upduser'),
            name: 'UpdUser',
            meta: {
                title: '管理员修改',
                noCache: true
            }
        }
        ]
    },

    {
        path: '/addConfig',
        component: Layout,
        hidden: true,
        children: [{
            path: 'index',
            component: () =>
                import('@/views/wx/add-config'),
            name: 'addConfig',
            meta: {
                title: '添加微信配置信息'
            }
        }]
    },
    {
        path: '/updConfig',
        component: Layout,
        hidden: true,
        children: [{
            path: 'index',
            component: () =>
                import('@/views/wx/upd-config'),
            name: 'updConfig',
            meta: {
                title: '修改微信配置信息'
            }
        }]
    },
    {
        path: '/orderInfo',
        component: Layout,
        redirect: '/orderInfo/index',
        hidden: true,
        children: [{
            path: 'index',
            component: () =>
                import('@/pages/mall/order/info'),
            name: 'orderInfo',
            meta: {
                title: '订单详情',
                noCache: true
            }
        },]
    },
    {
        path: '/infoRefund',
        component: Layout,
        redirect: '/infoRefund/index',
        hidden: true,
        children: [{
            path: 'index',
            component: () =>
                import('@/pages/mall/order/info-refund'),
            name: 'infoRefund',
            meta: {
                title: '退单详情',
                noCache: true
            }
        },]
    },
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

    // 404 page must be placed at the end !!!
    {
        path: '*',
        redirect: '/404',
        hidden: true
    },

]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router